package com.ruoyi.web.controller.visit;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.visit.domain.AdPenalty;
import com.ruoyi.visit.service.IAdPenaltyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 行政处罚Controller
 * 
 * @author ruoyi
 * @date 2021-08-23
 */
@RestController
@RequestMapping("/visit/penalty")
public class AdPenaltyController extends BaseController
{
    @Autowired
    private IAdPenaltyService adPenaltyService;

    /**
     * 查询行政处罚列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AdPenalty adPenalty)
    {
        startPage();
        List<AdPenalty> list = adPenaltyService.selectAdPenaltyList(adPenalty);
        return getDataTable(list);
    }

    /**
     * 导出行政处罚列表
     */
    @Log(title = "行政处罚", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AdPenalty adPenalty)
    {
        List<AdPenalty> list = adPenaltyService.selectAdPenaltyList(adPenalty);
        ExcelUtil<AdPenalty> util = new ExcelUtil<AdPenalty>(AdPenalty.class);
        return util.exportExcel(list, "行政处罚数据");
    }

    /**
     * 获取行政处罚详细信息
     */
    @GetMapping(value = "/{apId}")
    public AjaxResult getInfo(@PathVariable("apId") Long apId)
    {
        return AjaxResult.success(adPenaltyService.selectAdPenaltyById(apId));
    }

    /**
     * 新增行政处罚
     */
    @Log(title = "行政处罚", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdPenalty adPenalty)
    {
        return toAjax(adPenaltyService.insertAdPenalty(adPenalty));
    }

    /**
     * 修改行政处罚
     */
    @Log(title = "行政处罚", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdPenalty adPenalty)
    {
        return toAjax(adPenaltyService.updateAdPenalty(adPenalty));
    }

    /**
     * 删除行政处罚
     */
    @Log(title = "行政处罚", businessType = BusinessType.DELETE)
	@DeleteMapping("/{apIds}")
    public AjaxResult remove(@PathVariable Long[] apIds)
    {
        return toAjax(adPenaltyService.deleteAdPenaltyByIds(apIds));
    }
}
